package com.ithuaxin.comprehensiveractice;

import java.util.Random;
import java.util.Scanner;

public class Test7 {
    public static void main(String[] args) {
        int scoreArr[] = getScores();
        int maxSocre = getMax(scoreArr);
        int minSocre = getMin(scoreArr);
        int sum = getSum(scoreArr);
        int avg = (sum - maxSocre - minSocre) / (scoreArr.length - 2);
        System.out.println("平均分数为："+ avg);
    }

    public static int[] getScores(){
        Scanner sc = new Scanner(System.in);
        int scores[] = new int[6];
        for (int i = 0; i < scores.length;) {
            System.out.println("请输入学生的第"+ (i+1)+"个成绩");
            int score = sc.nextInt();
            if (score>=0 && score<=100){
                scores[i] = score;
                i++;
            }
            else{
                System.out.println("当前输入的数据无效，请重新输入，当前的i是"+ i);
            }
        }
        return scores;
    }
    public static int getMax(int []scoreArr){
        int max = scoreArr[0];
        for (int i = 0; i < scoreArr.length; i++) {
            if (max < scoreArr[i]){
                max = scoreArr[i];
            }
        }
        return max;
    }
    public static int getMin(int []scoreArr){
        int min = scoreArr[0];
        for (int i = 0; i < scoreArr.length; i++) {
            if (min > scoreArr[i]){
                min = scoreArr[i];
            }
        }
        return min;
    }
    public static int getSum(int []scoreArr){
        int sum = 0;
        for (int i = 0; i < scoreArr.length; i++) {
            sum = sum +scoreArr[i];
        }
        return sum;
    }
}
